package com.zmj.sy.mom.srv.aps.mapper;

import com.zmj.sy.mom.srv.aps.bean.entity.mes.Plate;
import com.zmj.sy.mom.srv.aps.bean.entity.mes.WorkDetailTask;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PlateMapper extends SyMapper<Plate> {

    @Select(" select part.part_id materCode, part.quantity totalCount, IFNULL(sum(task.total_count),0)  finishCount" +
            " from tb_third_sinocam_receive_nest_part part  " +
            " left join tb_third_sinocam_receive_nest_plate plate on plate.receive_nest_id = part.receive_nest_id " +
            " LEFT JOIN tb_third_sinocam_receive_nest nest ON plate.receive_nest_id = nest.id " +
            " LEFT JOIN tb_mes_work_detail_task task on task.part_id = part.id " +
            " where  plate.stock_list_no = #{plateCode}" +
            " group by part.part_id, part.quantity " +
            " ")
    List<WorkDetailTask> selectPlateFinishPart(@Param("plateCode") String plateCode);

    @Select("DELETE FROM tb_mes_plate WHERE id = #{id}")
    void deleteMesNest(@Param("id") Integer id);

    @Select("DELETE FROM tb_mes_plate WHERE mater_code = #{plateCode}")
    void deleteMesNestWithCode(@Param("plateCode") String plateCode);

}
